var curTypeId;
var curItemId;

$(function(){ 
	if(_isAli){
		IMPlayer.CheckConnection ();
		IMPlayer.UpdateStatusSignal.connect(OnStateChanged);
	}

	
	window.addEventListener("pageshow", pageShown, false);
	window.addEventListener("pagehide", pageHide, false);
	
	$('#justForPage').focus(function(){
		KEY.CURTYPE = false;
	}).click(function(){
		return false;
	});
});

function pageShown(){  
	curPlayData = false;
	if(typeList.length == 0){
		initData(afterInitData); 
	}else{
		afterInitData();
	}
	
}


function pageHide(){
	IMPlayer.Stop();
//	$.removeLocal("last_channel_play"); $.log("last_channel_play removeLocal");
	
}


function afterInitData(){
	KEY.PRESSTIME = true;
	
	var typeId=$.getSession('typeId');
	var itemId=$.getSession('itemId');  $.log(typeId+":"+itemId);
	if(typeId && itemId){
		curTypeId = parseInt(typeId,10); 
		curItemId = parseInt(itemId,10); 
	}else{
		var id=$.getSession('id'); 
		curTypeId = 1;
		curItemId = findItemId(id);
	}
	
	
	
	var type = typeList[curTypeId - 1]; 
	data = type.dataList[curItemId - 1];  
	
	play(data);

}

function findItemId(id){
	var dataList = typeList[0].dataList;
	var itemId = 1;
	for(var i = 1;i<=dataList.length;i++){
		if(dataList[i-1].id == id){
			itemId = i;
		}
	}
	return itemId;
}

function gotoPlayPage(data,typeId,itemId){
	curTypeId = typeId;
	curItemId = itemId;
	var type = typeList[curTypeId - 1]; 
	data = type.dataList[curItemId - 1];  
	
	play(data);
}